package com.snda.game.legend.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.snda.game.legend.entiy.Acticle;
import com.snda.game.legend.velocity.tools.DomainTool;

@Repository
public class ActicleDao extends BaseDao<Acticle> {
    private final DomainTool domainTool = new DomainTool();

    public List<Acticle> findAll() {
        Session session = getSession();
        String hql = "select new Acticle(id,title,updatetime) from Acticle  order by updatetime desc";
        @SuppressWarnings("unchecked")
        List<Acticle> acticles = session.createQuery(hql).list();
        releaseSession(session);
        return acticles;
    }

    public List<Acticle> findAll(boolean limit) {
        Session session = getSession();
        String hql = "select new Acticle( id,title,updatetime) from Acticle  order by updatetime desc";
        Query query = session.createQuery(hql);
        query.setFetchSize(Integer.parseInt(domainTool.info("size")));
        @SuppressWarnings({ "unchecked" })
        List<Acticle> acticles = query.list();
        releaseSession(session);
        return acticles;
    }

}
